<template>
    <div id="about">
        <div style="display: flex;justify-content: space-between;align-items: center;">
            <div style="color: #000000;font-weight: bold;" class="s-20">关于我们</div>
            <div @click="goback"  class="back">
                <img  src="../../../assets/img/person/back.png" alt="">
                <span class="s-15  pointer">返回</span>
            </div>
        </div>
        <div class="s-24 app-name">
            <img style="width: 372px;height: 79px;" src="../../../assets/img/person/about_logo.png" alt="">
            <div style="color: #FFFFFF;" class="s-16">帮助老师轻松上好每一节科学课</div>
            <div class="s-20" style="font-weight: bold;color: #FFFFFF;transform:translateY(48px)">版本号：{{ format(version) }}</div>
        </div>
        
        <div class="s-14 t-color-n description">
            {{  eduLevel==='primary'
                ?'美丽科学教学平台是为小学科学教师精心打造的专业备授课教学平台。平台是美丽科学团队与教育科学出版社联合研发出品，并获得教育部国家数字教育资源公共服务体系备案认证。平台数字资源同步新课标与《科学》教材，以科学可视化教学资源为特色，融合科学与艺术之美，激发学生兴趣。我们的愿景是帮助老师上好每一节科学课，让每一所学校的学生都能接受优质的科学教育。'
                :'美丽科学教学平台（中学版）是为中学教师打造的备授课教学资源平台。配套资源由人民教育出版社、广东教育出版社、中国化学会等多家权威机构与美丽科学合作开发。4K超清实验视频与新版、旧版教材匹配，采用微距、显微、延时、红外热成像等先进的摄影技术，将日常教学中难以观察到的实验现象，更直观地呈现给学生，可以极大的激发学生的学习兴趣，引导学生更积极的思考和实践。平台已获得教育部国家数字教育资源公共服务体系备案认证，已在全国约2500所中学成功应用。'
            }}
        </div>
        <div class="dash-border"></div>
        <div style="margin-top: 35px;">
            联系方式
        </div>
        <div class="flex-between service">
            <div class="service-container">
                <div class="service-item" style="margin-bottom:20px">
                    <img style="width: 19px;height: 19px;" src="../../../assets/img/person/phone.png" alt="">
                    <span class="s-16 t-color-m">联系电话：0551-62678653</span>
                </div>
                <div class="service-item">
                    <img style="width: 22px;height: 22px;" src="../../../assets/img/person/earth.png" alt="">
                    <span class="s-16 t-color-m">官方网站：<a href="javascript:void(0);" @click.prevent="openOfficialWebsite">www.beautyofscience.cn</a></span>
                </div>
            </div>
            <div class="service-container flex-end">
                <div class="service-item text-right">
                    <img style="width: 21px;height: 20px;" src="../../../assets/img/person/vx.png" alt="">
                    <span class="s-16 t-color-m">公众号：美丽科学教学平台</span>
                    <div class="s-14" style="margin-top:20px;color: #606266;">如需帮助，请扫码关注公众号，留言咨询在线客服</div>
                </div>
                <img class="code" :src="codeImg" alt="">
            </div>
        </div>
        <div class="s-14" style="color: #606266;text-align: center;width: 100%;">Copyright © 2023 新知数媒 保留所有权利</div>
    </div>
</template>

<script>
import { SqlLibUser } from '../../../../../../static/lib/sqlite/service/SqlLibUser'
import { SqlLib } from '../../../../../../static/lib/sqlite/SqlLib'
import { SqlLibBook } from "../../../../../../static/lib/sqlite/service/SqlLibBook";
import { getAppNewVersion } from '@/content/api/appversion'
import client from '@/content/utils/client'
import { UpdateApp } from '../../../utils/UpdateApp'
const path = require('path')
export default {
    data() {
        return {
            version: '',
            eduLevel: window.eduLevel
        }
    },
    computed: {
        aboutLogo() {
            if (this.eduLevel === 'primary') {
                return require('../../../assets/img/person/color-logo.png')
            } else {
                return require('../../../assets/img/person/icon-ms.png')
            }

        },
        codeImg() {
            if (this.eduLevel === 'primary') {
                return require('../../../assets/img/home/wechatqr.png')
            } else {
                return require('../../../assets/img/home/wechatqr.png')
            }
        }
    },
    mounted() {
        this.version = this.$readIniFile('data', 'versionInfo')
    },
    methods: {
        format(version){
            let versionText = version.substring(0,version.lastIndexOf('.'))
            return versionText
        },
        goback () {
            let sqlLib = SqlLib.getInstance(window.$DBDIR)
            let user = SqlLibUser.queryCurrentUser(sqlLib)
            let obj = {
                bookId: user.bookId
            }
            if (this.authorzation) {
                if (user.lessonId) {
                    obj.lessonId = user.lessonId
                } else {
                    let book = SqlLibBook.queryChapterLessonByBookId(sqlLib, user.bookId)
                    if (book) {
                        obj.lessonId = book[0].lessonVO[0].id
                    }
                }
            }
            this.$router.push({ name: 'home', params: this.authorzation ? obj : {} })
        },
        async checkUpdate() {
            // 调用接口获取最新版本号，并与当前版本比较
            let oldVersion = this.$readIniFile('data', 'ver')
            console.log(oldVersion);
            let res = await getAppNewVersion({
                clientType: '1',
                currentVersion:oldVersion,
            })
            let data = res.returnValue
            if (res.code !== '0') {
                this.$message.error('检查更新失败，请稍后重试')
            }
            if (oldVersion === data.currentVersion) {
                this.$message.success('您当前已是最新版本')
                return
            }
            if (oldVersion < data.currentVersion) {
                const path = require('path')
                let exePath = process.env.NODE_ENV === 'production' ? path.resolve(path.dirname(process.execPath), 'bos_updater.exe') : './bos_updater/bin/bos_updater'
                let exeParmsArr = [data.url, data.isGlobal === '0' ? '/e' : '/z', '']
                UpdateApp.update(exePath, exeParmsArr, { message: data.description, version: data.currentVersion, close: false, cancel: '取消', }, false);
            }else{
                this.$message.success('您当前已是最新版本')
            }

        },

        clearCache() {
            let rescDir = window.$DATADIR + '/resc';
            deleteFile(rescDir, '.zip');
            window.$Vue.$message({
                message: '下载缓存清除完成',
                center: true,
                type: 'success'
            });
        },

        openOfficialWebsite() {
            this.$client.openExternal("www.beautyofscience.cn")
        }
    }
}

// 递归删除特定后缀的文件
function deleteFile(dirPath, extname) {
    let fs = require('fs');
    let path = require('path');
    var files = [];
    if (fs.existsSync(dirPath)) {
        files = fs.readdirSync(dirPath);
        files.forEach(function (file, index) {
            var curPath = dirPath + "/" + file;
            if (fs.statSync(curPath).isDirectory()) {
                deleteFile(curPath, extname);
            } else {
                if (path.extname(curPath) === extname) {
                    fs.unlinkSync(curPath);
                }
            }
        });
    }
}
</script>

<style lang="scss">
#about {
    width: 100%;
    height: 100%;
    padding: 20px 30px;
    position: relative;
    .back {
        cursor: pointer;
        width: 88px;
        height: 32px;
        display: flex;
        justify-content: center;
        align-items: center;
        background: #0085FF;
        color: #FFFFFF;
        border-radius: 4px;
        border: 1px solid #D7D7D7;
        img{
            width: 8px;
            height: 11px;
            margin-right: 6px;
        }
    }
    .app-name {
        box-sizing: border-box;
        background-image: url(../../../assets/img/person/about_bg.png);
        background-size: cover;
        background-repeat: no-repeat;
        width: 100%;
        height: 297px;
        margin-top: 26px;
        margin-bottom: 13px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }
    .dash-border{
        margin-top: 100px;
        border-bottom: 1px dashed #DEE2E6;;
    }
    .check-update {
        background: #4894ff;
    }
    .about-button {
        width: 120px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border-radius: 8px;
        margin-top: 22px;
        margin-bottom: 41px;
        border: none;
        outline: none;
        color: #fff;
    }
    .clear-cache {
        background: #f56b6b;
    }
    .description {
        margin-top: 20px;
        line-height: 36px;
    }
    .service {
        width: 100%;
        margin-top: 20px;
        margin-bottom: 30px;
    }
    .service-item {
        img {
            width: 20px;
            height: 20px;
            margin-right: 10px;
        }
        a {
            text-decoration: underline;
            color: #4894ff;
        }
    }
    .code {
        width: 78px;
        height: 78px;
        margin-left: 18px;
    }
}
</style>
